import {setEntries, next, restart, vote, INITIAL_STATE} from './core';
import {TYPE_SET_ENTRIES, TYPE_NEXT, TYPE_RESTART, TYPE_VOTE} from './actions';

export default function reducer(state = INITIAL_STATE, action) {
  switch (action.type) {
    case TYPE_SET_ENTRIES:
      return setEntries(state, action.entries);
    case TYPE_NEXT:
      return next(state);
    case TYPE_RESTART:
      return restart(state);
    case TYPE_VOTE:
      return state.update('vote', voteState => vote(voteState, action.entry, action.clientId));
  }
  return state;
}
